using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Collections.Generic;

namespace WindowsRemoteScripting
{

    public class ScreenShot
    {
        public static bool saveToClipboard = false;

        protected static Bitmap m_Bitmap = null;

        public static Bitmap Bitmap
        {
            get { return m_Bitmap; }
            set { m_Bitmap = value; }
        }

        public static Bitmap CaptureImage(bool showCursor, Size curSize, Point curPos, Point SourcePoint, Point DestinationPoint, Rectangle SelectionRectangle, string FilePath, string extension)
        {
            m_Bitmap = new Bitmap(SelectionRectangle.Width, SelectionRectangle.Height);
            {
                using (Graphics g = Graphics.FromImage(m_Bitmap))
                {
                    g.CopyFromScreen(SourcePoint, DestinationPoint, SelectionRectangle.Size);

                    if (showCursor)
                    {
                        Rectangle cursorBounds = new Rectangle(curPos, curSize);
                        Cursors.Default.Draw(g, cursorBounds);
                    }

                    Form1.m_Form.pictureBoxArea.BackgroundImage = m_Bitmap;
                }

                if (saveToClipboard)
                {
                    Image img = (Image)m_Bitmap;
                    Clipboard.SetImage(img);
                }
                else
                {
                    //switch (extension)
                    //{
                    //    case ".bmp":
                    //        m_Bitmap.Save(FilePath, ImageFormat.Bmp);
                    //        break;

                    //    case ".jpg":
                    //        m_Bitmap.Save(FilePath, ImageFormat.Jpeg);
                    //        break;

                    //    case ".gif":
                    //        m_Bitmap.Save(FilePath, ImageFormat.Gif);
                    //        break;

                    //    case ".tiff":
                    //        m_Bitmap.Save(FilePath, ImageFormat.Tiff);
                    //        break;

                    //    case ".png":
                    //        m_Bitmap.Save(FilePath, ImageFormat.Png);
                    //        break;

                    //    default:
                    //        m_Bitmap.Save(FilePath, ImageFormat.Jpeg);
                    //        break;
                    //}
                }
            }
            return m_Bitmap;
        }
    }
}